'''
/*
 * @Author: wevsmy 
 * @Date: 2017-10-30 18:05:18 
 * @Last Modified by:   wevsmy 
 * @Last Modified time: 2017-10-30 18:05:18 
 */
'''
from socket import *

serverSocket = socket(AF_INET,SOCK_STREAM)

serverSocket.bind(("",8080))

serverSocket.setblocking(False)
serverSocket.listen(50)

ClientAdderList = []

while True:
    
    try:
        newSocket,destAdder = serverSocket.accept()
    except:
        pass
    else:
        print("一个新的客户端到来：%s"%str(destAdder))
        newSocket.setblocking(False)
        ClientAdderList.append((newSocket,destAdder))
    
    for clientSocket,clientAdder in ClientAdderList:
        try:
            recvData = clientSocket.recv(1024).decode("gb2312")
        except:
            pass
        else:
            if len(recvData)>0:
                print("recv[%s]:%s"%(str(clientAdder),recvData))
            else:
                clientSocket.close()
                ClientAdderList.remove((clientSocket,clientAdder))
                print('[%s]客户端已经关闭'%str(clientAdder))